package logic

import (
	"context"
	"gorm.io/gorm"
	"merchantmanager/merchantrpc/mysql"

	"merchantmanager/merchantrpc/internal/svc"
	"merchantmanager/merchantrpc/merchantrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowLogic {
	return &ShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 详情
func (l *ShowLogic) Show(in *merchantrpc.ShowRequest) (*merchantrpc.ShowResponse, error) {
	// todo: add your logic here and delete this line
	merchant := mysql.Merchant{
		Model: gorm.Model{ID: uint(in.Id)},
	}
	mysql.DB.Where("id = ?", in.Id).Find(&merchant)
	return &merchantrpc.ShowResponse{
		Id:      int64(merchant.ID),
		Name:    merchant.Name,
		Sex:     merchant.Sex,
		Age:     merchant.Age,
		Address: merchant.Address,
	}, nil
}
